package com.abso.sunlight.api;

import org.apache.commons.lang.StringUtils;

/** Legislator's party. */
public enum Party {

    DEMOCRATIC, REPUBLICAN, INDEPENDENT, UNKNOWN;

    /**
     * Gets the enum constant with the specified abbreviation.
     * 
     * @param abbr
     *            the party's abbreviation (D, R, or I).
     * @return the enum constant with the specified abbreviation.
     * @throws SunlightException
     *             if the abbreviation is invalid.
     */
    public static Party valueOfAbbreviation(String abbr) {
        if ("D".equals(abbr)) {
            return Party.DEMOCRATIC;
        } else if ("R".equals(abbr)) {
            return Party.REPUBLICAN;
        } else if ("I".equals(abbr)) {
            return Party.INDEPENDENT;
        } else {
            return Party.UNKNOWN;
        }
    }

    /**
     * Returns the party's abbreviation (D, R, or I).
     * 
     * @return the party's abbreviation.
     */
    public String getAbbreviation() {
        return name().substring(0, 1);
    }

    @Override
    public String toString() {
        return StringUtils.capitalize(this.name().toLowerCase());
    }

}
